<?php

namespace app\http\middleware;
use think\facade\Session;

class Check
{
    public function handle($request, \Closure $next)
    {
        if (empty($_SERVER['HTTP_TOKEN'])) {
            return \sendResponse('', 401);
        }

        //获取session中存入的uid
        $uid = Session::get('uid');
        //判断传入的uid和session中的是否一致
        if ($uid != $_SERVER['HTTP_TOKEN']) {
            return \sendResponse('', 401);
        }
        //将uid放入请求当中
        $request->uuid = (int)think_decrypt($uid);
        return $next($request);
    }
}
